package com.ys.service.hr.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.ys.dto.AddDto;
import com.ys.dto.EditDto;
import com.ys.entity.base.TbMaterial;
import com.ys.mapper.base.TbMaterialMapper;
import com.ys.service.hr.TbMaterialService;
import com.ys.vo.R;

@Service("tbMaterialService")
public class TbMaterialServiceImpl implements TbMaterialService {

	@Autowired
	private TbMaterialMapper tbMaterialMapper;

	@Override
	public R search(Map<String, Object> params) throws Exception {
		return null;
	}
	/**
	 * 新增
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@Override
	public R add(Map<String, Object> params) throws Exception {
		
		TbMaterial entity = JSON.parseObject(JSON.toJSONString(params), TbMaterial.class);

		tbMaterialMapper.insert(entity);
		return R.ok(AddDto.closeAndReload());
	}
	
	@Override
	@Transactional
	public R edit(Map<String, Object> params) throws Exception {
		TbMaterial entity = JSON.parseObject(JSON.toJSONString(params), TbMaterial.class);

		tbMaterialMapper.update(entity);
		return R.ok(EditDto.closeAndReload());
	}
}
